 int cmp (const void *a, const void *b) 
 {
     return *(int *)a - *(int *)b;
 }
int** threeSum(int* nums, int numsSize, int* returnSize, int** returnColumnSizes){
    int **ret = (int**)malloc(sizeof(int *) * 100000);
    *returnColumnSizes = (int *)malloc(sizeof(int) * 100000);
    int i,j;
    int cnt = 0;
    qsort(nums, numsSize, sizeof(int), cmp);
    for (i = 0; i < numsSize - 2; i++) {
        int left = i + 1;
        if (i != 0 && nums[i] == nums[i - 1]) {
            continue;
        }
  
        int right = numsSize - 1;
       printf("left%d  right%d  nums[left]%d nums[right]%d i = %d\n", left, right, nums[left], nums[right], i);
        while (left < right) {
            if (nums[left] + nums[right] == -nums[i]) {
               ret[cnt] = (int*)malloc(sizeof(int) * 3);
               memset(ret[cnt], 0, sizeof(int) * 3);
               int temp = nums[left];
              
                ret[cnt][0] = nums[i];
                ret[cnt][1] = nums[left];
                ret[cnt][2] = nums[right];
               printf("%d %d %d\n", ret[cnt][0],  ret[cnt][1],  ret[cnt][2]);
                 while (nums[left] == temp && left < right) {
                   left++;
               }
                cnt++;
            } else if (nums[left] + nums[right] > -nums[i]) {
                right--;
            } else {
                left++;
            }
        }

    }
    *returnSize = cnt;
    for (i = 0; i < cnt; i++) {
        (*returnColumnSizes)[i] = 3;
    }
    return ret;
}
